import React, { Component } from 'react';
import { connect } from 'react-redux'
import { Modal, Form, Input,Select ,DatePicker ,Table,Button,TreeSelect,  Popconfirm,Row,Col,
  InputNumber} from 'antd';
import { baseUrl } from '../../config/system';
const Option=Select.Option;
const FormItem = Form.Item;
const TreeNode = TreeSelect.TreeNode;

class DownLoadDetailModal extends Component {
  constructor(props) {
    super(props);
  }

  handleModelDownLoadSubmit=()=>{
    const { onOk } = this.props;
    this.props.form.validateFields((err, values) => {
      if (!err) {
        let param = JSON.stringify(values);
        param = encodeURIComponent(param);
        window.open(baseUrl+"/asset/downLoadEXLModel?param="+param);
      }
    });
  }

  

  render() {
    const { children, dispatch,onCancel,assetType } = this.props;
    const { getFieldDecorator,resetFields,getFieldProps,getFieldValue,setFieldsValue } = this.props.form;
    const formItemLayout = {
      labelCol: { span: 6 },
      wrapperCol: { span: 14 },
    };

    const typeTreeData = (i) => {
      return i.map( d => {
        d.label = d.name;
        d.key = d.id_+'';
        d.value = d.id_+'';
        d.children = d.assetType && d.assetType.length > 0 ? typeTreeData(d.assetType) : [];
        return d;
      })
   }

    const loop = data => data.map((item) => {
      if (item.assetType && item.assetType.length) {
        return <TreeNode key={item.id_+''} title={item.name} value={item.id_+''}>{loop(item.assetType)}</TreeNode>;
      }
      return <TreeNode key={item.id_+''} title={item.name} value={item.id_+''} />;
    });
    return (
      <span>
        <Modal
                maskClosable= {this.props.maskClosable}
                confirmLoading= {this.props.confirmLoading}
                title={this.props.title}
                visible={this.props.visible}
                 footer={[
                  <Button  key="close" type="primary" size="large" onClick={this.props.onCancel}>关闭</Button>,
                  <Button key="down" type="primary" size="large" onClick={this.handleModelDownLoadSubmit}>导出</Button>
                ]}
                onCancel={this.props.onCancel}
                key={this.props.newKey}
        >
         <Form horizontal>
           <FormItem   {...formItemLayout}
           hasFeedback label="资产分类">
             {
               getFieldDecorator('typeId',{
                 rules: [{
                   required: true, message: '请选择资产分类',
                 }]
               })(
               <TreeSelect
                 style={{ width: 200 }}
                 showSearch
                 treeNodeFilterProp="title"
                 dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
                 placeholder="请选择资产分类"
                 allowClear
                 treeDefaultExpandAll
                  treeData={typeTreeData(assetType)}       
               >
                    
               </TreeSelect>
               )
             }
           </FormItem>
          </Form>

        </Modal>

      </span>
    );
  }

}

export default Form.create()(DownLoadDetailModal)
